package com.mlyol.ocp;

public class Demo2 {

    public static void main(String[] args) {
        new Demo2().run();
    }

    void run() {
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Triangle());
    }
    class GraphicEditor {
        public void drawShape(Shape shape) {
            shape.draw();
        }
    }

    interface Shape {
         void draw();
    }

    class Rectangle implements Shape {
        @Override
        public void draw() {
            System.out.println("矩形");
        }
    }

    class Circle implements Shape {
        @Override
        public void draw() {
            System.out.println("圆形");
        }
    }

    // edit:1
    class Triangle implements Shape {
        @Override
        public void draw() {
            System.out.println("三角形");
        }
    }
}
